/*
** 3438.c
** 
** Made by (seakage2h)
** Login   <seakage2h@seakage2h-ubuntu>
** 
** Started on  Thu Oct 16 20:07:29 2008 seakage2h
** Last update Sun May 12 01:17:25 2002 Speed Blue
*/

/* #include "3438.h" */
#include <stdio.h>

int main()
{
     int instance, count;
     char cur, pre;

     instance = 0;
     while((cur = getchar()) != '\n')
	  instance = instance * 10 + cur - '0';

     while(instance--){
	  pre = getchar();
	  count = 1;
	  while((cur = getchar()) != '\n'){
	       if (cur == pre)
		    count++;
	       else{
		    printf("%d", count);
		    putchar(pre);
		    pre = cur;
		    count = 1;
	       }
	  }
	  printf("%d", count);
	  putchar(pre);
	  putchar('\n');
     }

     return 0;
}

